package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.pojo.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ljk74
 */
@RestController
@RequestMapping("admin/dish")
@Api(tags = "菜品管理")
@Slf4j
public class DishController {
    @Autowired
    private DishService dishService;

    @PostMapping
    @ApiOperation("新增菜品")
    public Result<String> addDish(@RequestBody DishDTO dishDTO) {
        dishService.addDish(dishDTO);
        return Result.success();
    }

    @GetMapping("/page")
    @ApiOperation("菜品分页查询")
    public Result<PageResult> pageQuery(DishPageQueryDTO dishPageQueryDTO){
        PageResult res = dishService.pageQuery(dishPageQueryDTO);
        return Result.success(res);
    }

    @DeleteMapping
    @ApiOperation("删除菜品")
    public Result<String> delDishes(@RequestParam("ids") List<Long> ids){
        dishService.delDishes(ids);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("根据分类id查询菜品")
    public Result<List<Dish>> findByCategoryId(Long categoryId){
        List<Dish> list = dishService.findByCategoryId(categoryId);
        return Result.success(list);
    }

    @GetMapping("/{dishId}")
    @ApiOperation("根据id查询菜品和其口味")
    public Result<DishVO> selectDishWithFlavor(@PathVariable Long dishId){
        DishVO dishVO = dishService.selectDishWithFlavor(dishId);
        return Result.success(dishVO);
    }

    @PutMapping
    @ApiOperation("修改菜品信息")
    public Result<String> updateDish(@RequestBody DishDTO dishDTO){
        dishService.updateDish(dishDTO);
        return Result.success();
    }

    @PostMapping("/status/{status}")
    @ApiOperation("修改起售/停售状态")
    public Result<String> startOrStop(@PathVariable("status")Integer status,Long id){
        dishService.startOrStop(status,id);
        return Result.success();
    }
}
